package com.sk.bilibili.model.fragment.main.home.home;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.R;
import com.sk.bilibili.dto.Extra;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.PropagandaMapper;
import com.sk.bilibili.mapper.ThemBannerMapper;
import com.sk.bilibili.mapper.ThemMapper;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.main.home.home.FilmFragment;

import java.util.ArrayList;
import java.util.List;

public class FilmModel extends BaseRefreshModel<FilmFragment> {

    @Autowired
    ThemBannerMapper themBannerMapper;
    @Autowired
    FollowThemMapper followThemMapper;
    private int size=100;
    @Autowired
    ThemMapper themMapper;
    @Autowired
    PropagandaMapper propagandaMapper;
    private List<Extra> list;

    public FilmModel() {
        list=new ArrayList<>();
        list.add(new Extra(R.drawable.film_documentary,"纪录片"));
        list.add(new Extra(R.drawable.film_film,"电影"));
        list.add(new Extra(R.drawable.film_tv,"电视剧"));
        list.add(new Extra(R.drawable.film_rank,"热门榜单"));
        list.add(new Extra(R.drawable.film_meat,"深夜食堂"));
    }

    @Override
    public void refreshData() {
        RequestUtils.process(themBannerMapper.getThemBanner(3), themBanners ->
                view.loadBannerSuccess(themBanners));
        JsonMap map=new JsonMap();
        map.put("size",size);
        map.put("typeId",3);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage ->
                view.loadFollowThemSuccess(followThemPage.getRecords()));
        RequestUtils.process(themMapper.getRank(3, 3), thems -> view.loadRankSuccess(thems));
        RequestUtils.process(themMapper.getRandom(null,6, 2), thems -> view.loadHotThemSuccess(thems));
        RequestUtils.process(propagandaMapper.getAll(), propagandas -> view.loadPropagandaSuccess(propagandas));
        view.loadTypeSuccess(list);
    }

    public void followThem(Integer id) {
        JsonMap map = new JsonMap();
        map.put("themId", id);
        RequestUtils.process(followThemMapper.add(map), unused -> view.followThemSuccess());
    }

}